package com.tool.lock.redisson;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 酒徒
 * @Version 1.0
 * @data 2025/6/29 16:27
 */
@RestController
@RequestMapping("/lock")
public class LockController {
    @Autowired
    private RedissonClient redissonClient;

    @RequestMapping("/redisson")
    public String redisson() {
        String res = "res";
        RLock lock = redissonClient.getLock("lock");
        if (lock.tryLock()) {
            try {
                res = "res1";
                System.out.println("获取锁成功");
            } finally {
                lock.unlock();
            }
        }
        return res;
    }

}
